import { createStore, applyMiddleware, compose } from 'redux';
import reducer from './reducer'
import createSagaMiddleware from 'redux-saga'
import todoSagas from './sagas'

// create the saga middleware
const sagaMiddleware = createSagaMiddleware()

// import thunk from 'redux-thunk'
// redux三大原则
// store是唯一的
// 只有store能够改变自己的内容
// Reducer必须是纯函数

// redux核心API
// createStore  store.dispath  store.getState  store.subscribe

// redux-thunk 异步请求的处理，将异步代码都放到redux中间件，有助于做自动化测试以及代码的拆分管理

// 纯函数指的是，给定固定的输入，就一定会有固定的输出，而且不会有任何副作用
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose;
const enhancer = composeEnhancers(
  applyMiddleware(sagaMiddleware),
);
const store = new createStore(reducer, enhancer);
sagaMiddleware.run(todoSagas)

export default store; 